<template>
	<div class="product-list">
		<div class="product-content">
			<div class="common-seach-wrap">
			

			<el-form size="small" :inline="true" :model="searchForm" class="demo-form-inline">
				<el-form-item label="供应商名称">
					<el-input size="small" clearable v-model="searchForm.supplier_name"  placeholder="请输入"></el-input>
				</el-form-item>

				<el-form-item label="供应商电话">
					<el-input size="small" clearable v-model="searchForm.link_phone"  placeholder="请输入"></el-input>
				</el-form-item>

				<el-form-item>
					<el-button size="small" type="primary" icon="Search" @click="onSubmit">查询</el-button>
				</el-form-item>
			</el-form>
		</div>
			<div class="table-wrap">
				<el-table ref="table" size="small" :data="tableData" border style="width: 100%" v-loading="loading"
					@selection-change="handleSelectionChange">
					>
					<el-table-column type="index"  width="50" label="序号" align="center"  />

					<el-table-column prop="share_supplier_name" label="供应商" align="center">
					</el-table-column>

					<el-table-column prop="link_phone" label="供应商手机号" align="center">
					</el-table-column>
					
					<el-table-column prop="name" label="接龙名称" align="center"></el-table-column>
					<el-table-column prop="img" label="图片" align="center">
						<template #default="scope">
							<img :src="scope.row.img" style="width: 50px; margin:auto">
						</template>
					</el-table-column>
					<el-table-column prop="time_start" label="接龙截止时间" align="center">
						<template #default="scope">
							<span>{{scope.row.time_start}}</span>
						</template>
					</el-table-column>
					<el-table-column prop="time_end" label="接龙截止时间" align="center">
						<template #default="scope">
							<span>{{scope.row.time_end}}</span>
						</template>
					</el-table-column>
					
					<el-table-column prop="share_status" label="状态" align="center">
						<template #default="scope">
							<span>{{scope.row.share_status.text}}</span>
						</template>
					</el-table-column>
					<el-table-column fixed="right" label="操作" align="center" width="270">
						<template #default="scope" >
							<div>
								<!-- <el-button  link type="primary" size="small"
									>查看</el-button> -->

								<el-button @click="acceptShareTuan(scope.row)" link type="primary" size="small"
									>接受</el-button>
							</div>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>
		<!--分页-->
		<div class="pagination">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background
				:current-page="curPage" :page-size="pageSize" layout="total, prev, pager, next, jumper"
				:total="totalDataNumber"></el-pagination>
		</div>
	</div>
</template>

<script>
import {
	wait_accept_list,
	apiAcceptShareTuan,
	delete_share
} from "@/api/tuan.js";

export default {
	components: {},
	data() {
		return {
			/*切换菜单*/
			activeName: "sell",
			/*切换选中值*/
			activeIndex: "0",
			/*是否正在加载*/
			loading: true,
			/*一页多少条*/
			pageSize: 10,
			/*一共多少条数据*/
			totalDataNumber: 0,
			/*当前是第几页*/
			curPage: 1,
			/*搜索参数*/
			searchForm: {
				supplier_name: '', //供应商名称
				link_phone: '',   // 供应商手机号

			},
			/*列表数据*/
			tableData: [],
			/*全部分类*/
			categoryList: [],
			supplier: [],
			/*统计数据*/
			product_count: {},
			// 列表选中项
			selectedRows: [],
		};
	},
	created() {
		/*获取列表*/
		this.getList();
	},
	methods: {
		
		/*搜索查询*/
		onSubmit() {
			this.curPage = 1;
			this.getList();
		},


		// 点击接受接龙
		async acceptShareTuan(row) {
			let params = {
				share_tuan_id: row.share_tuan_id
			}
			let data = await apiAcceptShareTuan(params);
			console.log(data)
			if (data.code == 1) {
				console.log(data.data)
				this.curPage = 1
				this.getList()
			} else {
				ElMessage.error(data.msg);
			}
		},

		// 删除
		async del(row) {
			let params = {
				id: row.id
			}
			let data = await delete_share(params);
			console.log(data)
			if (data.code == 1) {
				console.log(data.data)
				this.curPage = 1
				this.getList()
			
			} else {
				ElMessage.error(data.msg);
			}
		},

		// 获取列表
		async getList() {
			let params = {
				page: this.curPage,
				list_rows: this.pageSize,
				...this.searchForm
			}
			this.loading = true;
			let data = await wait_accept_list(params);
			console.log(data)
			if (data.code == 1) {
				console.log(data.data)
				this.loading = false;
				this.tableData = data.data.data;
				this.totalDataNumber = data.data.data.total;
			} else {
				ElMessage.error(data.msg);
			}
		},

		/*选择第几页*/
		handleCurrentChange(val) {
			let self = this;
			self.loading = true;
			self.curPage = val;
			self.getList();
		},

		/*每页多少条*/
		handleSizeChange(val) {
			this.pageSize = val;
			this.getList();
		},

		/*删除*/
		delClick: function (row) {
			let self = this;
			let msg =  "删除后不可恢复，确认删除吗?";
			ElMessageBox.confirm(msg, "提示", {
				type: "warning",
			}).then(() => {
				this.del()
			});
		},
	},
};
</script>

<style>
.head-part {
	display: flex;
	align-items: center;
}

.el-form-item--small .el-form-item__content {
    line-height: 1 !important;
}
</style>
